<template>
    <el-main>
        <el-main class="ep-body">
            <epl-top-bar :datas="{formData:form}" showPerson psTagType="PERSON_PENSION_QUERY"
                         personType="PERSON_ALL_EXACT">
            </epl-top-bar>
            <epl-userMessage dataType="person" idCount="8">
            </epl-userMessage>
            <el-card class="ep-card">
                <el-tabs v-model="activeName2" type="card">
                    <el-tab-pane label="精减人员定期待遇信息" name="1">
                        <ep-table :data="tableData1" edited="true" :pager="20">
                            <ep-table-column editor="text" name="aaa036" header="待遇项目"></ep-table-column>
                            <ep-table-column editor="text" name="aaa037" header="待遇项目名称"></ep-table-column>
                            <ep-table-column editor="text" name="aae019" header="待遇项目金额"></ep-table-column>
                            <ep-table-column editor="text" name="aae041" header="待遇开始年月"></ep-table-column>
                        </ep-table>
                    </el-tab-pane>
                    <el-tab-pane label="调整方式" name="2">
                        <ep-table :data="tableData2" :pager="20">
                            <ep-table-column editor="text" name="aaa036" header="待调整待遇项目"></ep-table-column>
                            <ep-table-column editor="text" name="aaa037" header="待调整待遇项目名称"></ep-table-column>
                            <ep-table-column editor="text" name="aae041" header="调整开始年月"></ep-table-column>
                            <ep-table-column editor="text" name="changeway" header="调整方式"></ep-table-column>
                            <ep-table-column editor="text" name="aae019s" header="调整值"></ep-table-column>
                            <ep-table-column editor="text" name="aae019" header="调整到值"></ep-table-column>
                            <ep-table-column editor="text" name="aae013" header="备注"></ep-table-column>
                        </ep-table>
                    </el-tab-pane>
                    <el-tab-pane label="待遇补扣信息" name="3">
                        <ep-table :data="tableData3" :pager="20" rowDbClick>
                            <ep-table-column editor="text" header="调整前金额" name="aae019"></ep-table-column>
                            <ep-table-column editor="text" header="调整后金额" name="aae019s"></ep-table-column>
                            <ep-table-column editor="text" header="调整幅度值" name="changenum"></ep-table-column>
                            <ep-table-column editor="text" header="补扣发总金额" name="totalmoney"></ep-table-column>
                            <ep-table-column editor="text" header="补扣发总月数" name="totalmonths"></ep-table-column>
                        </ep-table>
                    </el-tab-pane>
                </el-tabs>
                <el-row type="flex" justify="center">
                    <ep-button id="cal" api="doQuery" type="primary" top="20" bottom="20"
                               :datas="{formData: form,tableData1:tableData1,panel:panel}"
                               name="计算"></ep-button>
                    <ep-saveButton id="doSave" type="primary" top="20"  bottom="20" ref="save" @formValidate="formValidate" :validate="['form']"
                                   :datas="{formData: form,panel:panel}" name="保存"></ep-saveButton>
                </el-row>
            </el-card>
        </el-main>
    </el-main>
</template>
<script type="es6">
    export default {
        data() {
            return {
                activeName2: '1',
                tableData1: {},
                tableData2: {},
                tableData3: {},
                panel: {},

                rules:{

                },
                codeTypes:{

                },
                codeTypeFilters:{

                },
                pager: {
                    page: 1,
                    size: 10
                },
                total: 0,
            }
        },
        computed: {
            functionId() {
                if (this.$store.getters.init.path !== this.$route.path) return;
                if (this.$store.getters.init.mdParam === null || this.$store.getters.init.mdParam === undefined) return;
                if (this.$store.getters.init.mdParam.functionid === undefined) return;
                return this.$store.getters.init.mdParam.functionid;
            },
            backFun() {
                return this.$store.getters.backFun;
            },
            init_formData() {
                if (this.$store.getters.init.path !== this.$route.path)  return;
                return this.$store.getters.init.form;
            },
            doInitformData: {
                get: function () {
                    if (this.$store.getters.common === null) return [];
                    if (this.$store.getters.common.path !== this.$route.path) return;
                    return this.$store.getters.common.formData;
                },
                set: function (newValue) {
                    if (newValue.path !== this.$route.path) return;
                    return newValue;
                }
            },
            init_panel() {
                if (this.$store.getters.init.path !== this.$route.path)  return;
                return this.$store.getters.init.panel;
            },
            doInitpanel: {
                get: function () {
                    if (this.$store.getters.common === null) return [];
                    if (this.$store.getters.common.path !== this.$route.path) return;
                    return this.$store.getters.common.panel;
                },
                set: function (newValue) {
                    if (newValue.path !== this.$route.path) return;
                    return newValue;
                }
            },

        },
        created() {
            let param = {
                path: this.$route.path,
                codeTypes:this.codeTypes,
                codeTypeFilters: window.btoa(JSON.stringify(this.codeTypeFilters)),
                tableData1:this.tableData1,
                tableData2:this.tableData2,
                tableData3:this.tableData3,
                panel:this.panel

            };
            if (this.$route.query.keepAlive === undefined) {
                this.$store.dispatch('SET_INIT', param);
            }
        },
        watch: {
            init_formData: {
                handler(value) {
                    if (value == undefined) return;
                    this.getformData(value);
                },
                deep: true
            },
            doInitformData: {
                handler(value) {
                    if (value == undefined) return;
                    this.getformData(value);
                },
                deep: true
            },
            init_panel: {
                handler(value) {
                    if (value == undefined) return;
                    this.getpanel(value);
                },
                deep: true
            },
            doInitpanel: {
                handler(value) {
                    if (value == undefined) return;
                    this.getpanel(value);
                },
                deep: true
            },

            backFun: {
                handler(value) {
                    if (value === null) return;
                    this.customBackFun();
                    let backFun = [];
                    backFun = value.split(',');
                    if (backFun.indexOf('rDoInit') >= 0) {
                        let codeTypes = {

                        };
                        let tableData1= {};
                        let tableData2= {};
                        let tableData3= {};
                        let panel= {};

                        let param = {
                            path: this.$route.path,
                            codeTypes:codeTypes,
                            codeTypeFilters: window.btoa(JSON.stringify(this.codeTypeFilters)),
                            tableData1:tableData1,
                            tableData2:tableData2,
                            tableData3:tableData3,
                            panel:panel

                        };
                        this.$store.dispatch('SET_INIT', param);
                    }
                }
            }
        },
        mounted() {
            if (this.$store.getters.cacheData === null) return;
            if (this.$store.getters.cacheData[this.$route.path] === undefined)  return;
            if (this.$store.getters.cacheData[this.$route.path].path !== this.$route.path) return;
            if (this.$store.getters.cacheData[this.$route.path].form !== undefined) {
                this.getformData(this.$store.getters.cacheData[this.$route.path].form);
            }
            if (this.$store.getters.cacheData[this.$route.path].panel !== undefined) {
                this.getpanel(this.$store.getters.cacheData[this.$route.path].panel);
            }

        },
        beforeRouteLeave(to, from, next) {
            let param = {
                path: this.$route.path,
                codeTypes: this.$store.getters.codeTypes,
                codeTypeFilters: window.btoa(JSON.stringify(this.codeTypeFilters)),
                tableData1:this.tableData1,
                tableData2:this.tableData2,
                tableData3:this.tableData3,
                panel:this.panel

            };
            if (from) {
                this.$store.dispatch('SET_CACHEDATA', param);
            }
            next();
        },
        methods: {
            getformData(value) {
                this.form = value;
            },
            getpanel(value) {
                this.panel = value;
            },


            handleSizeChange(val) {
                console.log(`每页 ${val} 条`);
            },
            handleCurrentChange(val) {
                console.log(`当前页: ${val}`);
            },
            handleEdit(id) {
                this.dialogFormVisible = true;
            },
            formValidate(value){
                if(value && value.length>0){
                    let btn = true;
                    value.forEach((item,index)=>{
                        if(!btn) return
                        this.$refs[item].validate((valid) => {
                            if (valid) {
                                btn = true;
                            } else {
                                btn = false;
                            }
                        });
                    })
                    if(btn) this.$refs.save.btn();
                }
            },

            customBackFun(){//自定义方法体
            },
        },
    }
</script>
